package com.wangyadong.hobby.jmh;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.AverageTime)
@State(Scope.Benchmark)
@Warmup(iterations = 2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Measurement(iterations = 2)
@Threads(5)
public class JMHExample003 {

//    @Param({"1", "3", "4"})
//    private int type;
    private Map<Long, Long> map = new LinkedHashMap();

    @Setup
    public void setUp() {
//        if (type == 1) {
//            map = new ConcurrentHashMap();
//        } else if (type == 2) {
//
//        } else if (type == 3) {
//            map = new ConcurrentSkipListMap<>();
//        } else if (type == 4) {
//            map = new LinkedHashMap();
//        }
        System.out.println(LocalDateTime.now().toString());
    }

    @Benchmark
    public String map() {
        long l = System.nanoTime();
        map.put(l, l);
        return null;
    }


    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder().include(JMHExample003.class.getSimpleName())
                .forks(1)
                .build();
        new Runner(options).run();
    }
}
